"""
名片管理系统
"""
# 定义全局变量
quit_flag = False
cards = []


# 菜单打印
def menu():
    print("*" * 50)
    print("""欢迎使用名片管理系统:
    1. 新建名片
    2. 显示名片
    3. 查询名片
    0. 退出系统""")
    print("*" * 50)


def new_card():
    name = input("请输入姓名:")
    phone = input("请输入手机号:")
    email = input("请输入邮箱:")
    card_dict = {"name": name, "phone": phone, "email": email}
    cards.append(card_dict)
    print("用户名片信息,添加成功!!!")


def show_card():
    for card in cards:
        print("姓名: %s\t手机号: %s\t邮箱: %s" % (card["name"], card["phone"], card["email"]))


def query_card(key_word):
    for card in cards:
        if key_word in card.values():
            return card
    else:
        return None


def quit_card():
    global quit_flag
    print("欢迎下次使用名片管理系统!!!")
    quit_flag = True


menu()


while True:
    if quit_flag:
        break
    op = input("请输入操作序号:")
    if op == '1':
        new_card()
    elif op == '2':
        show_card()
    elif op == '3':
        keyword = input("请输入查询条件:")
        query_card(keyword)

    elif op == '0':
        quit_card()
    else:
        print('输入有误, 请重新输入')
